package com.yaoxun.console.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yaoxun.console.code.BaseResponseCode;
import com.yaoxun.console.service.NamespaceService;
import com.yaoxun.console.xo.req.NamespaceEditReq;
import com.yaoxun.console.xo.req.NamespaceListReq;
import com.yaoxun.console.xo.resp.ApiResp;
import com.yaoxun.console.xo.resp.BooResp;
import com.yaoxun.console.xo.resp.NamespaceResp;
import com.yaoxun.console.xo.resp.PageInfo;

@Controller
@RequestMapping("/namespace")
public class NamespaceController implements BaseController {

	@Autowired
	private NamespaceService namespaceService;
	
	@ResponseBody
	@PostMapping("/add")
	public ApiResp<BooResp> add(@Validated @RequestBody NamespaceEditReq req) {
		namespaceService.add(req);
		return ofRo(BaseResponseCode.ADD_SUCCESS, BooResp.of(true));
	}
	
	@ResponseBody
	@PostMapping("/list")
	public ApiResp<PageInfo<NamespaceResp>> list(@RequestBody NamespaceListReq req) {
		PageInfo<NamespaceResp> pageInfo = namespaceService.list(req);
		return ofRo(BaseResponseCode.SEARCH_SUCCESS, pageInfo);
	}
	
	@ResponseBody
	@PostMapping("/delete")
	public ApiResp<BooResp> delete(@Validated @RequestBody NamespaceEditReq req) {
		namespaceService.delete(req);
		return ofRo(BaseResponseCode.DELETE_SUCCESS, BooResp.of(true));
	}
	
}
